
import 'package:flutter/foundation.dart';
import 'package:flutter_wan_android/feature/core/ui_state.dart';

abstract class BaseViewModel extends ChangeNotifier{
  UiState _uiState = UiState.loading();

  String _errorMsg = "";

  int _errorCode = -1;

  String get message  => _errorMsg;

  UiState get uiState  => _uiState;

  int get code => _errorCode;

  void notifyError(String msg,{int code = -1}){
    _errorCode = code;
    _errorMsg = msg;
    _uiState = UiState.error();
    notifyListeners();
  }

  void notifyLoading(){
    _uiState = UiState.loading();
    notifyListeners();
  }

  void notifySuccess({int code = 0}){
    _errorCode = code;
    _uiState = UiState.success();
    notifyListeners();
  }
}